package com.UI
{
	import com.*;
	import com.Engine.*;
	import com.Packet.*;
	
	import flash.display.*;
	import flash.events.*;
	import flash.external.*;
	import flash.filters.*;
	import flash.geom.*;
	import flash.system.*;
	import flash.text.*;
	import flash.ui.*;
	import flash.utils.*;
	
	import gs.*;
	import gs.easing.*;
	import gs.events.TweenEvent;
	
	import org.aswing.*;
	import org.aswing.border.*;
	import org.aswing.border.EmptyBorder;
	import org.aswing.colorchooser.*;
	import org.aswing.dnd.*;
	import org.aswing.event.*;
	import org.aswing.ext.*;
	import org.aswing.geom.*;
	import org.aswing.tree.AbstractLayoutCache;
	public class FrameAddStamina extends JFrame
	{
		//members define
		private var labelTimer:JLabel;
		private var textArea:JTextArea;
		private var panelItemIcon:JPanel;
		private var btnUse:JButton;
		
		
		//-----------------------------------
		private var btn_close:JButton;
		public function FrameAddStamina()
		{
			setResizable(false);  
			setBorder(new EmptyBorder());
			btn_close = new JButton();
			btn_close.setSize(new IntDimension(27, 27));
			btn_close.setPreferredSize(new IntDimension(27, 27));
			this.getTitleBar().setCloseButton(btn_close);
			this.getTitleBar().setMinimizeHeight(32);
			getContentPane().setBorder(new EmptyBorder());

			//component creation
			setSize(new IntDimension(260, 139));
			setPreferredSize(new IntDimension(260, 139));
			var layout0:EmptyLayout = new EmptyLayout();
			getContentPane().setLayout(layout0);
			
			labelTimer = new JLabel();
			labelTimer.setLocation(new IntPoint(8, 0));
			labelTimer.setSize(new IntDimension(245, 14));
			labelTimer.setPreferredSize(new IntDimension(245, 14));
			labelTimer.setText("label");
			labelTimer.setHorizontalAlignment(AsWingConstants.CENTER);
			
			textArea = new JTextArea();
			textArea.setLocation(new IntPoint(8, 14));
			textArea.setSize(new IntDimension(245, 50));
			textArea.setPreferredSize(new IntDimension(245, 50));
			textArea.setText("体力每5分钟恢复一点.空闲时间可以访问好友幻境.");
			textArea.setEditable(false);
			textArea.setWordWrap(true);
			
			panelItemIcon = new JPanel();
			panelItemIcon.setLocation(new IntPoint(84, 76));
			panelItemIcon.setSize(new IntDimension(42, 42));
			panelItemIcon.setPreferredSize(new IntDimension(42, 42));
			
			btnUse = new JButton();
			btnUse.setLocation(new IntPoint(173, 85));
			btnUse.setSize(new IntDimension(49, 25));
			btnUse.setPreferredSize(new IntDimension(49, 25));
			btnUse.setText("使用");
			
			//component layoution
			getContentPane().append(labelTimer);
			getContentPane().append(textArea);
			getContentPane().append(panelItemIcon);
			getContentPane().append(btnUse);

			setImages();
		}

		private function onRollOver(event:MouseEvent):void
		{
			var target:JPanel = event.target as JPanel;
			if(!(target.getBorder() is EmptyBorder))
				return;
			target.setBorder(new LineBorder(null,ASColor.GREEN));
		}
		
		private function onRollOut(event:MouseEvent):void
		{
			var target:JPanel = event.target as JPanel;
			target.setBorder(new EmptyBorder());
		}
		public function setImages():void
		{
			btn_close.wrapSimpleButton(Client.getUIElement("btn_close") as SimpleButton);
			var img_background:DisplayObject = Client.getUIElement("img_add_stamina_bg") as DisplayObject
			setBackgroundDecorator(new AssetBackground(img_background));
			setSizeWH(img_background.width,img_background.height);
			setLocationXY((Engine.W - width) / 2,(Engine.H - height)/2);

			textArea.setForeground(ASColor.WHITE);
			textArea.setEditable(false);
			textArea.setWordWrap(true);
			textArea.setBackgroundDecorator(null);
			
			var filter:GlowFilter;
			var font:ASFont = new ASFont("宋体", 12, false, false, false, false);
			filter = new GlowFilter(0x000000, 1, 2, 2, 10);
			
			labelTimer.setFont(font);
			labelTimer.setForeground(ASColor.ORANGE);
			labelTimer.setTextFilters(new Array(filter));
			
			textArea.setFont(font);
			textArea.setForeground(ASColor.WHITE);
			textArea.filters = (new Array(filter));
			
			btnUse.wrapSimpleButton(Client.getUIElement("btn_add_use") as SimpleButton);
			btnUse.setText("");

			
			panelItemIcon.addEventListener(MouseEvent.ROLL_OVER, onRollOver);
			panelItemIcon.addEventListener(MouseEvent.ROLL_OUT, onRollOut);
			btnUse.addActionListener(onBtnUse);
			
		}
		
		private function onBtnUse(event:Event):void
		{
			PanelMain.showInfoTimeLimit("没有找到相关道具");
		}
		
		
		private static var _frame:FrameAddStamina = null;
		public static function show():void
		{
			if(isShowing())
			{
				_frame.hide();
				return;
			}
			if(_frame == null)
			{
				_frame = new FrameAddStamina();
				PanelMainHelp.getInstance().addChild(_frame);
			}
			_frame.show();
			PanelMainHelp.getInstance().bringToTop(_frame);
			
			Client.getInstance().sendPacketLogic(12,[1,0]);
			Client.getInstance().sendPacketLogic(12,[2,0]);
			
			_frame.x = (Engine.W - _frame.width) / 2;
			_frame.y = (Engine.H - _frame.height) / 2;
			update()
			
		}
		public static function hide():void
		{
			if(isShowing())_frame.hide();
		}
		public static function isShowing():Boolean
		{
			return(_frame != null&& _frame.isShowing());
		}
		
		static public function phLackStamina_503(e:PacketEvent):void
		{
			
			var msg:Array = e.data as Array;
			trace("phLackStamina_503", msg);
			if(!FrameAddStamina.isShowing())
				FrameAddStamina.show();
		}
		public static function update():void
		{
			if(!isShowing())
				return;
			_frame.labelTimer.setText(PanelMainHelp.formatTime(5*60-CharInfo.staminaUpdateTime)+" 后恢复");
			var str:String = new String;
			str+="空闲时间可以访问好友幻境."
			_frame.textArea.setHtmlText(str);
		}
	}
}